<?php if(!defined('DB_NAME')) die();
	//特色图像
	if(function_exists('add_theme_support')) add_theme_support('post-thumbnails');
	//截取缩略图
	if(get('ini_thumb')!="TimThumb"){
		add_image_size('large',430,230,true);
		add_image_size('medium',110,110,true);
	}
	// 获取缩略图
	function ini_thumb($width, $height, $tag = 0 ){
		if( get('ini_no_thumb') ) return;
		global $post;
		$postid = $post->ID;
		$title = strip_tags( $post->post_title );
		// 从元数据提取缩略图
		$image = get_post_meta( $postid, "thumb", TRUE );
		if( $image != null || $image != "" ){
			$img_src = $image;
		}
		// 获取特色图像
		elseif( function_exists("has_post_thumbnail") && has_post_thumbnail() ){
			$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full');
			$img_src = $thumbnail_src[0];
		} else {
			// 获取第一张图
			preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $matches );
			$first_img = $matches[1][0];
			if( !empty( $first_img ) ){
				$img_src = $first_img;
			} else {
				// 使用随机图片
				$img_src = TPDIR.'/res/img/';
				$img_src.= $width > 110 ? 'big'.rand(1,6) : 'small'.rand(1,6);
				$img_src.= '.jpg';
			}
		}
		// 检索是否开启TimThumb
		if( get('ini_thumb')!="TimThumb" ){
			$thumb = ini_old_thumb($width, $height);
		} else {
			$thumb = TPDIR."/timthumb.php?src={$img_src}&w={$width}&h={$height}&zc=1";
		}
		return $tag == 1 ? "<img src=\"$thumb\" width=\"$width\" height=\"$height\" alt=\"$title\"/>" : $thumb;
	}
	$obj_key =$new_average;
	// 兼容旧版本缩略图
	function ini_old_thumb($width, $height){
		global $post;
		if( $width>110 ){
			$thumb_size = "large";
		} else {
			$thumb_size = "medium";
		}
		$image = get_post_meta( $post->ID, "thumb", TRUE );
		if( $image != null || $image != "" ){
			$old_thumb = $image;
		}
		elseif ( function_exists("has_post_thumbnail") && has_post_thumbnail() ){
			$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id($postid), $thumb_size);
			$old_thumb = $thumbnail_src[0];
		} else {
			preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $matches );
			if(!empty($matches[1][0])){
				$old_thumb = $matches[1][0];
			} else {
				$old_thumb = TPDIR.'/res/img/';
				$old_thumb.= $width > 110 ? 'big'.rand(1,6) : 'small'.rand(1,6);
				$old_thumb.= '.jpg"';
			}
		}
		return $old_thumb;
	}
	// 输出缩略图
	function ini_img($width, $height){
		echo ini_thumb($width, $height, 1);
	}
	// 输出缩略图，包含div
	function get_img($width, $height){
		if( get('ini_no_thumb') ) return;
		echo "<div class=\"thumbnail\"><a href=\"" . get_permalink() . "\">" . ini_thumb($width, $height, 1) . "</a></div>\n";
	}
	// 幻灯片缩略图
	function ini_featured(){
		echo "<li><a href=\"" . get_permalink() . "\">" . ini_thumb(430, 230, 1) . "<h2 class=\"featured-title\">" . get_the_title() . "</h2></a></li>\n";
	}